;;; Code:
(require 'json)
(require 'url)

(defgroup teahour nil
  "Read all teahour in one place"
  :group 'external
  :prefix "teahour-")

(defface one-link-face
  '((t
     (:underline
      (:color foreground-color :style line)
      :foreground "#6699cc")))
  "Face used for links to articles"
  :group 'one)

(defvar teahour-url "http://www.teahour.fm")

(defconst teahour-channels-delimiter "==================================================================================================="
  "Delimiter for channels show.")

(defvar teahour-mode-map nil
  "Keymap for teahour mode.")

(setq teahour-mode-map
      (let ((map (make-sparse-keymap)))
        ;(define-key map (kbd "RET") 'douban-music-goto-current-playing)
        ;(define-key map "r" 'douban-music-refresh)
        ;(define-key map "j" 'douban-music-current-song-info)
        (define-key map "c" 'select-number)
        ;(define-key map "n" 'douban-music-play-next-refresh)
        ;(define-key map "p" 'douban-music-play-previous)
        ;(define-key map "q" 'douban-music-bury-buffer)
        (define-key map "x" 'teahour-quit)
        ;(define-key map " " 'douban-music-pause/resume)
        ;(define-key map "<" 'douban-music-seek-backward)
        ;(define-key map ">" 'douban-music-seek-forward)
        map))



(defconst teahour-header-line
  '("    "
    (:propertize "n p" face mode-line-buffer-id)
    ": Navigate"
    "    "
    (:propertize "RET" face mode-line-buffer-id)
    ": Visit externally"
    "    "
    (:propertize "t" face mode-line-buffer-id)
    ": Visit"
    "    "
    (:propertize "q" face mode-line-buffer-id)
    ": Quit")
  "Header-line used in `one-mode'.")

(defun teahour-ui ()
  (insert (concat (propertize "Teahour"
                              'face '(:height 1.3 :foreground "Grey70"))
                  (propertize "FM"
                              'face '(:height 1.4 :foreground "ForestGreen"))
                  (propertize " teahour.fm\n\n"
                              'face '(:height 0.8 :foreground "grey70" :))))
  (insert (propertize "名称:"
                      'face '(:foreground "Grey70" :height 1.1)))
  (insert (propertize (format "%s%s" "                        " "介绍:")
                      'face '(:foreground "Grey70" :height 1.1)))

  (insert (propertize (format "\n%s"
                              teahour-channels-delimiter)
                      'face '(:foreground "Grey80")))

  (let (line-format
        (lines '("a" "b" "c")))
    (while lines
      (progn
        (setq line-format (propertize (format "\n%s%s%s%s" " " (pop lines) "                        " "xxxxxxxxxx")
                                      'face '(:foreground "#924678" :height 1.1)))
        (insert line-format))))

  )

(defun select-number (num)
  ""
  (interactive "Number:::")
  (message num))


(defun buf ()
  (with-output-to-temp-buffer "*teahour*"
    (switch-to-buffer "*teahour*")
    (setq font-lock-mode nil)
    (erase-buffer)
    (setq header-line-format teahour-header-line)
    (setq major-mode 'teahour-mode)
    (use-local-map teahour-mode-map)
    (teahour-ui)))



(defun teahour-quit ()
  "quit teahour mode."
  (interactive)
  (when (eq major-mode 'teahour-mode)
   ; (douban-music-stop)
    (kill-buffer (current-buffer))))



;;;autoload
(defun teahour ()
  (interactive)
  (kill-all-local-variables)
  (setq major-mode 'teahour-mode)
  (setq mode-name "Teahour-FM")
  ;(use-local-map teahour-mode-map)
  (buf))

(provide 'teahour-mode)
;;; teahour-mode.el ends here
